package com.k.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.k.demo.entity.UserAddress;
import com.k.demo.mapper.UserAddressMapper;
import com.k.demo.service.UserAddressService;

@Service
public class UserAddressServiceImpl implements UserAddressService{

	@Autowired
	private UserAddressMapper userAddressMapper;
	
	@Override
	public List<UserAddress> getALL() {
		
		return userAddressMapper.seletAll();
		
	}

	//获取当前用户的地址列表
	public List<UserAddress> getNowAddresses(int userid) {
		// TODO Auto-generated method stub
		return userAddressMapper.selectNowAddresses(userid);
	}

	//增加用户地址
	public UserAddress addUserAddress(UserAddress userAddress) {
		
		int count = userAddressMapper.insertUserAddress(userAddress);
		
		if(count > 0 ) {
			return userAddress;
		}
		
		return null;
	}
	
	//假删除用户地址
	public UserAddress falseDeleteUserAddress(int address_id) {
		int count = userAddressMapper.falseDeleteUserAddress(address_id);
		
		System.out.println("假删除用户的地址:"+count);
		
		if(count > 0) {
			return userAddressMapper.selectAddressById(address_id);
		}
		
		return null;
	}

	//统计当前用户下的地址数量
	public int countUserAddress(int userid) {
		
		return userAddressMapper.countUserAddress(userid);
	}

	//修改某个地址
	public UserAddress modifyUserAddress(UserAddress userAddress) {
		int count = userAddressMapper.modifyUserAddress(userAddress);
		
		if(count > 0) {
			return userAddressMapper.selectAddressById(userAddress.getAddress_id());
		}
		
		return null;
	}

	//默认地址更新
	public int updatedefult(int userid) {
		
		int count = userAddressMapper.updateDefult(userid);
		
		return count;
	}
	
	
	//更新

}
